#!/usr/bin/env ruby

# Copyright (c) 2010-2012 Microsoft Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#	http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'rubygems'
require 'ruby-aws'

if ARGV.length < 2
	$stderr.puts("Usage: #{$0} <resuls-file1> <results-file2>")
	exit
end

results1 = Amazon::Util::DataReader.load(ARGV[0], :Tabular)
results2 = Amazon::Util::DataReader.load(ARGV[1], :Tabular)

workers1 = results1.inject({}) do |h, v|
	workerId = v[:WorkerId]
	h[workerId] ||= 0
	h[workerId]  += 1
	h
end

workers2 = results2.inject({}) do |h, v|
	workerId = v[:WorkerId]
	h[workerId] ||= 0
	h[workerId]  += 1
	h
end

puts "Number of workers in #1: #{workers1.keys.length}"
puts "Number of workers in #2: #{workers2.keys.length}"

puts "Number of workers unique to #1: #{(workers1.keys - workers2.keys).length}"
puts "Number of workers unique to #2: #{(workers2.keys - workers1.keys).length}"
puts "Number of workers common to #1 and #2: #{(workers1.keys & workers2.keys).length}"
puts ""

puts "Number of assignments in #1: " + workers1.keys.inject(0) { |total, workerId| total += workers1[workerId] }.to_s
puts "Number of assignments in #2: " + workers2.keys.inject(0) { |total, workerId| total += workers2[workerId] }.to_s

puts "Number of assignments in #1 from workers unique to #1: " + (workers1.keys - workers2.keys).inject(0) { |total, workerId| total += workers1[workerId] }.to_s
puts "Number of assignments in #2 from workers unique to #2: " + (workers2.keys - workers1.keys).inject(0) { |total, workerId| total += workers2[workerId] }.to_s
puts "Number of assignments in #1 from workers common to #1 and #2: " + (workers1.keys & workers2.keys).inject(0) { |total, workerId| total += workers1[workerId] }.to_s
puts "Number of assignments in #2 from workers common to #1 and #2: " + (workers1.keys & workers2.keys).inject(0) { |total, workerId| total += workers2[workerId] }.to_s

